<div class="dux-page-header am-cf">
    <div class="page-title">
        <a class="am-btn am-btn-primary" href="{url('index', ['class_id' => $classId])}"> 商品列表</a>
    </div>
    <div class="page-action">
        <a class="am-btn am-btn-danger" href="javascript:location.reload();"><i class="am-icon-refresh"></i></a>
    </div>
</div>

<form class="am-form dux-form" data-dux="form-bind" method="post">
    <div class="am-g">
        <div class="am-u-lg-8">
            <div class="am-panel am-panel-default dux-panel">

                <div class="am-panel-hd">{$assignName}商品</div>
                <div class="am-panel-bd">
                    <fieldset>
                        <div class="am-form-group">
                            <label class="am-form-label">商品分类</label>
                            <div>
                                <select data-am-selected="{btnWidth: '100%'}" name="class_id" id="class_id" required>
                                    <!--loop{(array)$classList as $vo}-->
                                    <option <!--if{$vo.class_id == $classId}--> selected <!--{/if}-->
                                    value="{$vo.class_id}">{$vo.cname}</option>
                                    <!--{/loop}-->
                                </select>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">商品标题</label>
                            <div>
                                <input type="text" name="title" value="{$info.title}" placeholder="请输入商品标题"
                                       required>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">商品品牌</label>
                            <div>
                                <select  data-dux="form-chosen" data-placeholder="选择商品品牌" name="brand_id">
                                    <option value="0"></option>
                                    <!--loop{(array)$brandList as $vo}-->
                                    <option <!--if{$vo.brand_id == $info.brand_id}--> selected <!--{/if}-->
                                    value="{$vo.brand_id}">{$vo.name}</option>
                                    <!--{/loop}-->
                                </select>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">推荐位</label>
                            <div>
                                <?php $posIds = explode(',', $info['pos_id']); ?>
                                <select name="pos_id[]" multiple data-am-selected="{btnWidth: '100%'}">
                                    <!--loop{$posList as $vo}-->
                                    <option value="{$vo.pos_id}" <!--if{in_array($vo.pos_id, $posIds)}--> selected
                                    <!--{/if}-->>{$vo.name}</option>
                                    <!--{/loop}-->
                                </select>
                            </div>
                        </div>




                    </fieldset>
                </div>
            </div>

            <div class="am-panel am-panel-default dux-panel">
                <div class="am-panel-hd">商品图片(建议上传图片最多不超过5张)</div>
                <div class="am-panel-bd">
                    <button class="am-btn am-btn-success" type="button" data-dux="form-images"
                            data-img-list='{json_encode(unserialize($info.images))}' data-img-name="images"
                            data-img-warp="#dux-images-images"
                            data-type="jpg,png,bmp" data-resize="{width : 500, height: 500, crop: true}">上传组图
                    </button>
                    <div class="dux-images am-cf" id="dux-images-images"></div>

                </div>
            </div>


            <div class="am-panel am-panel-default dux-panel">
                <div class="am-panel-hd">
                    商品规格
                </div>
                <div class="am-panel-bd">
                    <!--if{!$info.spec_group_id}-->
                    <div class="am-margin-bottom">
                        <button class="am-btn am-btn-success" type="button" id="add-spec">设置规格</button>
                    </div>
                    <!--{/if}-->
                    <div class="js-data-list"></div>
                </div>
            </div>


            <div class="am-panel am-panel-default dux-panel">
                <div class="am-panel-hd">
                    商品属性(可选)
                </div>
                <div class="am-panel-bd">
                    <div class="am-form-group">
                        <label class="am-form-label">选择属性</label>
                        <div>
                            <select name="filter_id" class="select-filter" data-dux="form-chosen" style="width: 100%" data-placeholder="请选择商品筛选属性" tabindex="-1">
                                <option value="0"></option>
                                <!--loop{(array)$filterList as $key => $vo}-->
                                <option value="{$vo.filter_id}" {$info.filter_id ? 'selected' : ''} >{$vo.name}</option>
                                <!--{/loop}-->
                            </select>
                        </div>
                    </div>


                    <div class="filter-body">
                        {$filterHtml}
                    </div>
                </div>
            </div>

            <div class="am-panel am-panel-default dux-panel">
                <div class="am-panel-hd">商品详情</div>
                <div class="am-panel-bd">
                    <div class="am-form-group">
                        <label class="am-form-label">详情内容</label>
                        <div>
                            <textarea data-dux="form-editor" name="content" id="content"
                                      style="height: 500px">{$info.content}</textarea>
                        </div>
                    </div>

                    {$modelHtml}

                    <div class="am-form-group">
                        <label class="am-form-label">关键词</label>
                        <div>
                            <input type="text" name="keyword" value="{$info.keyword}" data-dux="form-tags"
                                   placeholder="可选,商品关键词">
                        </div>
                    </div>
                    <div class="am-form-group">
                        <label class="am-form-label">商品描述</label>
                        <div>
                            <textarea name="description" placeholder="可选,商品描述">{$info.description}</textarea>
                        </div>
                    </div>

                    <input type="hidden" name="content_id" value="{$info.content_id}">
                    <input type="hidden" name="shop_id" value="{$info.shop_id}">
                    <input type="hidden" name="app" value="shop">
                    <button class="am-btn am-btn-primary" type="submit" disabled>保存</button>
                </div>
            </div>
        </div>
        <div class="am-u-lg-4">
            <div class="am-panel am-panel-default dux-panel">

                <div class="am-panel-hd">其他信息</div>
                <div class="am-panel-bd">
                        <div class="am-form-group">
                            <label class="am-form-label">副标题</label>
                            <div>
                                <input type="text" name="subtitle" value="{$info.subtitle}" placeholder="请输入副标题名称">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">商品单位</label>
                            <div>
                                <input type="text" name="unit" value="{$info.unit ? $info.unit : '个'}"
                                       placeholder="单个商品单位"
                                       required>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">发布时间</label>
                            <div>
                                <input type="text" data-dux="form-date" data-format="yyyy-mm-dd hh:ii"
                                       name="create_time"
                                       value="{$info.create_time ? date('Y-m-d H:i', $info.create_time) : date('Y-m-d H:i')}"
                                       placeholder="商品发布时间">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">上架时间</label>
                            <div>
                                <input type="text" data-dux="form-date" data-format="yyyy-mm-dd hh:ii"
                                       name="up_time"
                                       value="{$info.up_time ? date('Y-m-d H:i', $info.up_time) : ''}"
                                       placeholder="商品上架时间">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">下架时间</label>
                            <div>
                                <input type="text" data-dux="form-date" data-format="yyyy-mm-dd hh:ii"
                                       name="down_time"
                                       value="{$info.down_time ? date('Y-m-d H:i', $info.down_time) : ''}"
                                       placeholder="商品下架时间">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">商品顺序</label>
                            <div>
                                <input type="text" name="sort" value="{$info.sort ? $info.sort : 0}"
                                       placeholder="链接排序,按照从小->大排序列表">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">外部链接</label>
                            <div>
                                <input type="text" name="url" value="{$info.url}" placeholder="请输入链接地址">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">模板名称</label>
                            <div>
                                <select data-dux="form-chosen" name="tpl" required>
                                    <option value="">==默认==</option>
                                    <!--loop{$tplList as $vo}-->
                                    <option value="{$vo.value}" <!--if{$info.tpl == $vo.value}-->  selected <!--{/if}-->
                                    >{$vo.name}</option>
                                    <!--{/loop}-->
                                </select>

                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">浏览量</label>
                            <div>
                                <input type="number" name="view" value="{$info.view}" placeholder="商品浏览次数">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">商品状态</label>
                            <div>
                                <?php $info['status'] = isset($info['status']) ? $info['status'] : 1;  ?>
                                <label class="am-radio-inline">
                                    <!--if{$info['status']}-->
                                    <input name="status" value="1" checked="checked" type="radio">
                                    <!--{else}-->
                                    <input name="status" value="1" type="radio">
                                    <!--{/if}-->
                                    正常
                                </label>
                                <label class="am-radio-inline">
                                    <!--if{!$info['status']}-->
                                    <input name="status" checked="checked" value="0" type="radio">
                                    <!--{else}-->
                                    <input name="status" value="0" type="radio">
                                    <!--{/if}-->
                                    隐藏
                                </label>
                            </div>
                        </div>
                </div>
            </div>
            {$hookHtml}
        </div>
    </div>

</form>


<script id="tpl-spec" type="text/html">
    {{# var specList = d.data.spec_list; }}
    {{# var specCount = specList.length; }}
    <div class="am-scrollable-horizontal">
    <table class="am-table dux-table-dialog  am-text-nowrap">
        <thead>
        <tr>
            <th>商品货号</th>
            {{# var head = d.head; }}
            {{# for(var i in head){ }}
            <th>{{ head[i].name }}</th>
            {{# } }}
            <th width="80">销售价</th>
            <th width="80">市场价</th>
            <th width="80">成本价</th>
            <th width="80">库存</th>
            <th width="80">重量(克)</th>
            <th width="80">积分</th>
            {{# if(specCount > 1){ }}
            <th class="uk-text-center" width="60">操作</th>
            {{# } }}
        </tr>
        </thead>
        <tbody>
        {{# for(var i in specList){ }}
        <tr>
            <input type="hidden" name="data[id][{{ i }}]" {{# if(!$.isEmptyObject(d.data.id[i])){ }}
                   value="{{ d.data.id[i] }}" {{# } }}/>
            <td><input class="goods_no" type="text" name="data[goods_no][{{ i }}]" {{# if(!$.isEmptyObject(d.data.goods_no[i])){ }} value="{{ d.data.goods_no[i] }}" {{# }else{ }}
                       value="{{ defaultProductNo+'_'+i }}" {{# } }}></td>
            {{# for(var item in specList[i]){ }}
            <input type="hidden" name="data[spec][{{ i }}][]" value='{{ JSON.stringify(specList[i][item]) }}'>
            <td>{{ specList[i][item].value }}</td>
            {{# } }}
            <td><input class="sell_price" type="text" name="data[sell_price][{{ i }}]" {{# if(!$.isEmptyObject(d.data.sell_price[i])){ }} value="{{ d.data.sell_price[i] }}" {{# } }}></td>
            <td><input class="market_price" type="text" name="data[market_price][{{ i }}]" {{# if(!$.isEmptyObject(d.data.market_price[i])){ }} value="{{ d.data.market_price[i] }}" {{# } }}>
            </td>
            <td><input class="cost_price" type="text" name="data[cost_price][{{ i }}]" {{# if(!$.isEmptyObject(d.data.cost_price[i])){ }} value="{{ d.data.cost_price[i] }}" {{# } }}></td>
            <td><input class="store" type="text" name="data[store][{{ i }}]" {{# if(!$.isEmptyObject(d.data.store[i])){ }} value="{{ d.data.store[i] }}" {{# } }}></td>
            <td><input class="weight" type="text" name="data[weight][{{ i }}]" {{# if(!$.isEmptyObject(d.data.weight[i])){ }} value="{{ d.data.weight[i] }}" {{# } }}></td>
            <td><input class="point" type="text" name="data[point][{{ i }}]" {{# if(!$.isEmptyObject(d.data.point[i])){ }} value="{{ d.data.point[i] }}" {{# } }}></td>
            {{# if(specCount > 1){ }}
            <td class="am-text-center">
                <a href="javascript:;" class="am-btn am-btn-danger am-btn-sm js-del am-icon-remove"></a>
            </td>
            {{# } }}
        </tr>
        {{# } }}
        </tbody>
    </table>
    </div>
</script>
<script id="tpl-spec-default" type="text/html">
    <div class="am-scrollable-horizontal">
    <table class="am-table dux-table-dialog  am-text-nowrap">
        <thead>
        <tr>
            <th>商品货号</th>
            <th width="80">销售价</th>
            <th width="80">市场价</th>
            <th width="80">成本价</th>
            <th width="80">库存</th>
            <th width="80">重量(克)</th>
            <th width="80">积分</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td><input class="goods_no" type="text" name="data[goods_no][0]" value="{{ d.no }}"></td>
            <td><input class="sell_price" type="text" name="data[sell_price][0]" value=""></td>
            <td><input class="market_price" type="text" name="data[market_price][0]" value=""></td>
            <td><input class="cost_price" type="text" name="data[cost_price][0]" value=""></td>
            <td><input class="cost_price" type="text" name="data[store][0]" value=""></td>
            <td><input class="weight" type="text" name="data[weight][0]" value=""></td>
            <td><input class="point" type="text" name="data[point][0]" value=""></td>
        </tr>
        </tbody>
    </table>
    </div>
</script>


<script>
    var defaultProductNo = '{$productNo}';
    var proDataJson = {$proDataJson};
    var proHeadJson = {$proHeadJson};
    Do('base', 'chosen','tpl', function () {

        $('.select-filter').chosen().change(function () {
            app.ajax({
                url : '{url("site/Filter/filterHtml")}?id=' + $(this).val(),
                type : 'post',
                success : function (html) {
                    $('.filter-body').html(html);
                }
            });
        });

        dialog.open($('#add-spec'), {
            title: '添加规格',
            width : '640px',
            height: '480px',
            url: '{url("specDialog")}?class_id=' + $('#class_id').val()
        });
        window.addData = function addData(head, data) {
            if(head.length < 1) {
                return false;
            }
            var gettpl = $('#tpl-spec').html();
            laytpl(gettpl).render({data: data, head: head}, function (html) {
                $('.js-data-list').html(html);
            });
        };
        $('.js-data-list').on('click', '.js-del', function () {
            if ($('.js-data-list tbody').find('tr').length > 1) {
                $(this).parents('tr').remove();
            } else {
                addDefaultData();
            }
        });
        function addDefaultData() {
            var gettpl = $('#tpl-spec-default').html();
            laytpl(gettpl).render({no: defaultProductNo}, function (html) {
                $('.js-data-list').html(html);
            });
        }

        if ($.isEmptyObject(proDataJson)) {
            addDefaultData();
        } else {
            addData(proHeadJson, proDataJson);
        }


    });
</script>